﻿var _class;

var ClassArr=_class;////类别数据
////set类别名称
function setClassName(){
    var x = document.getElementById("ClassID").value;
    if(x){
        var a = GetClassNameByclassID(x);
        if(a){ClassName(a);}
    }
}
////类别名称
function ClassName(x){
    var classname=document.getElementById("ClassName");
    if(!classname){
        return;
    }
    if(x){
        classname.innerHTML="原(" + x + ") <br/>";
    }else{
        return classname.innerHTML;
    }
}

function selectColor()
{
    if(document.getElementById("RadioButtonList_Color_0").checked)
    {
        document.getElementById("ColorDiv").style.display="";
    }else{
        document.getElementById("ColorDiv").style.display="none";
    }
}

function selectSize()
{
    if(document.getElementById("RadioButtonList_Size_0").checked)
    {
        document.getElementById("SizeDiv").style.display="";
    }else{
        document.getElementById("SizeDiv").style.display="none";
    }
}

function AddSize()
{
        var a = document.getElementById("Text_Size").value;
        a = a.replace(/(^\s*)|(\s*$)/g, "");
    if(a!=""){
        document.getElementById('Text_SizeSum').value+=a+","; 
        document.getElementById("Text_Size").value="";
   } 
}

function ClearSize()
{
    document.getElementById('Text_SizeSum').value="";
}

function GetClassNameByclassID(ID){
    var c = "";
    var ClassArray=new Array();
    for(var x in ClassArr){
	   if(x==ID){
	      var _classArray=_class[x];
	      c = _classArray[0];
	      if(_classArray[1]!="0")
	      {
	          c = GetClassNameByclassID(_classArray[1]) + " > " + c;
	      }
	      break;
	   }
    }
    return c;
}


function GetClassByParentID(ParentID){
  var ClassArray=new Array();
  for(var x in _class){
     var _classArray=_class[x]
	 if(_classArray[1]==ParentID){
	    var _array=new Array();
		_array[0]=_classArray[0];
		_array[1]=x;
        _array[2]=_classArray[2];
		ClassArray.push(_array);        
	 }
  } 
  return ClassArray;
}

function Hidden(x){
    var obj = document.getElementById("table"+x);
    if(obj.style.display==""){
        obj.style.display="none";
    }else{
        obj.style.display="";
    }
}

function selectTypeCode(bojvalue){
    
    if(bojvalue=="1"){
        document.getElementById("display_productType_1").style.display="";
        document.getElementById("display_productType_2").style.display="none";
        document.getElementById("display_productType_3").style.display="none";
        document.getElementById("display_productType_4").style.display="none";
        document.getElementById("trHavaTime").style.display="";
        document.getElementById("trTime").style.display="";
        
        //SelectNone(bojvalue);
        
    }else if(bojvalue=="2"){
        document.getElementById("display_productType_2").style.display="";
        document.getElementById("display_productType_1").style.display="none";
        document.getElementById("display_productType_3").style.display="none";
        document.getElementById("display_productType_4").style.display = "none";
        document.getElementById("display_productType_5").style.display="none";
        // document.getElementById("trWaterPrice").style.display="none";
        document.getElementById("trProcessFee").style.display="none";
        document.getElementById("trHavaTime").style.display="";
        document.getElementById("trTime").style.display="";
        SelectNone(bojvalue);

    }else if(bojvalue=="3"){
        document.getElementById("display_productType_3").style.display="";
        document.getElementById("display_productType_1").style.display="none";
        document.getElementById("display_productType_2").style.display="none";
        document.getElementById("display_productType_4").style.display = "none";
        document.getElementById("display_productType_5").style.display="none";
        // document.getElementById("trWaterPrice").style.display="none";
        document.getElementById("trProcessFee").style.display="none";
        document.getElementById("trHavaTime").style.display="";
        document.getElementById("trTime").style.display="";
        //SelectNone(bojvalue);
    }
    else if(bojvalue=="4"){
        document.getElementById("display_productType_4").style.display="";
        document.getElementById("display_productType_1").style.display="none";
        document.getElementById("display_productType_2").style.display="none";
        document.getElementById("display_productType_3").style.display="none";
        document.getElementById("display_productType_5").style.display="none";
       // document.getElementById("trWaterPrice").style.display="none";
        document.getElementById("trProcessFee").style.display="none";
        document.getElementById("trHavaTime").style.display="none";
        document.getElementById("trTime").style.display="none";
        //SelectNone(bojvalue);
    }
    else if(bojvalue=="5"){
        document.getElementById("display_productType_5").style.display="";
        document.getElementById("display_productType_1").style.display="none";
        document.getElementById("display_productType_2").style.display="none";
        document.getElementById("display_productType_3").style.display="none";
        document.getElementById("display_productType_4").style.display="none";
     //  document.getElementById("trWaterPrice").style.display="";
        document.getElementById("trProcessFee").style.display="";
        document.getElementById("trHavaTime").style.display="";
        document.getElementById("trTime").style.display="";
    }
}

function selectType(){
    var boj = document.getElementsByName("RadioButtonList_ProductType");
    var bojvalue;
    for(i=0;i<boj.length;i++){
        if(boj[i].checked)
            bojvalue = boj[i].value;
    }
    
    if(bojvalue=="1"){
        document.getElementById("display_productType_1").style.display="";
        document.getElementById("display_productType_2").style.display="none";
        document.getElementById("display_productType_3").style.display="none";
        document.getElementById("display_productType_4").style.display = "none";
        document.getElementById("display_productType_5").style.display="none";
       // document.getElementById("trWaterPrice").style.display="none";
       // document.getElementById("trProcessFee").style.display="none";
        document.getElementById("HiddenTr").style.display = "";
        document.getElementById("trHavaTime").style.display="";
        document.getElementById("trTime").style.display="";
        
       // SelectNone(bojvalue);
        
    }else if(bojvalue=="2"){
        document.getElementById("display_productType_2").style.display="";
        document.getElementById("display_productType_1").style.display="none";
        document.getElementById("display_productType_3").style.display="none";
        document.getElementById("display_productType_4").style.display = "none";
                document.getElementById("display_productType_5").style.display="none";
      //  document.getElementById("trWaterPrice").style.display="none";
       // document.getElementById("trProcessFee").style.display="none";
        document.getElementById("HiddenTr").style.display = "none";
        document.getElementById("trHavaTime").style.display="";
        document.getElementById("trTime").style.display="";
        //SelectNone(bojvalue);

    }else if(bojvalue=="3"){
        document.getElementById("display_productType_3").style.display="";
        document.getElementById("display_productType_1").style.display="none";
        document.getElementById("display_productType_2").style.display="none";
        document.getElementById("display_productType_4").style.display = "none";
        document.getElementById("display_productType_5").style.display="none";
      //  document.getElementById("trWaterPrice").style.display="none";
       // document.getElementById("trProcessFee").style.display="none";
        document.getElementById("HiddenTr").style.display = "none";
        document.getElementById("trHavaTime").style.display="";
        document.getElementById("trTime").style.display="";
       // SelectNone(bojvalue);
    }
    else if(bojvalue=="4"){
        document.getElementById("display_productType_4").style.display="";
        document.getElementById("display_productType_1").style.display="none";
        document.getElementById("display_productType_2").style.display="none";
        document.getElementById("display_productType_3").style.display = "none";
        document.getElementById("display_productType_5").style.display="none";
      //  document.getElementById("trWaterPrice").style.display="none";
      //  document.getElementById("trProcessFee").style.display="none";
        document.getElementById("HiddenTr").style.display = "";
        document.getElementById("trHavaTime").style.display="none";
        document.getElementById("trTime").style.display="none";
       // SelectNone(bojvalue);
    }
    else if(bojvalue=="5"){
        document.getElementById("display_productType_5").style.display="";
        document.getElementById("display_productType_3").style.display="none";
        document.getElementById("display_productType_1").style.display="none";
        document.getElementById("display_productType_2").style.display="none";
        document.getElementById("display_productType_4").style.display = "none";
      //  document.getElementById("trWaterPrice").style.display="";
       // document.getElementById("trProcessFee").style.display="";
        document.getElementById("HiddenTr").style.display = "none";
        document.getElementById("trHavaTime").style.display="";
        document.getElementById("trTime").style.display="";
    }
}
function selectVideoType(){
    if(document.getElementById("proudct_video_type_0").checked){
        document.getElementById("proudct_video_type_url_div").style.display="";
        document.getElementById("proudct_video_type_upload_div").style.display="none";
    }else if(document.getElementById("proudct_video_type_1").checked){
        document.getElementById("proudct_video_type_url_div").style.display="none";
        document.getElementById("proudct_video_type_upload_div").style.display="";
    }
}
function changeTeam(){
    var obj = document.getElementById("DropTeamNum");
    var objvalue = obj.options[obj.selectedIndex].value;
    for(var i=1;i<=5;i++){
        if(i<=objvalue){
            document.getElementById("team_"+i).style.display="";
        }else{
            document.getElementById("team_"+i).style.display="none";
        }
    }
}
function selectProductPublishTime()
{
    if(document.getElementById("ProductPublishTime_1").checked)
    {
        document.getElementById("PublishStartTr").style.display="";
    }else{
        document.getElementById("PublishStartTr").style.display="none";
    }
}


function selectNeedInvoice()
{
    if(document.getElementById("NeedInvoice_0").checked)
    {
        document.getElementById("NeedInvoiceDiv").style.display="";
    }else{
        document.getElementById("NeedInvoiceDiv").style.display="none";
    }
}


function CheckSubmit(){
    var MM_ProductType = document.getElementsByName("RadioButtonList_ProductType");
    var ProductTypevalue;
    for(i=0;i<MM_ProductType.length;i++){
        if(MM_ProductType[i].checked)
            ProductTypevalue = MM_ProductType[i].value;
    }
    
    if(ProductTypevalue=="6"){
        if(document.getElementById("WitkeyTaskTitle").value==""){
        alert("请填写任务标题！");
        document.getElementById("WitkeyTaskTitle").focus();
        return false;
        }
    }
    else{
    
    
    if(document.getElementById("ProductName").value==""){
        alert("请填写商品名称！");
        document.getElementById("ProductName").focus();
        return false;
    }
    

    if(ProductTypevalue=="1"){
        if(document.getElementById("StandPrice").value==""){
            alert("请填写商品价格！");
            document.getElementById("StandPrice").focus();
            return false;
        }
    }else if(ProductTypevalue=="2"){
        if(document.getElementById("AuctionPrice").value==""){
            alert("请填写商品起拍价！");
            document.getElementById("AuctionPrice").focus();
            return false;
        }
        if(document.getElementById("AuctionAddPrice").value==""){
            alert("请填写商品加价幅度！");
            document.getElementById("AuctionAddPrice").focus();
            return false;
        }
    }else if(ProductTypevalue=="3"){
        if(document.getElementById("OriginallyPrice").value==""){
            alert("请填写商品原始价！");
            document.getElementById("OriginallyPrice").focus();
            return false;
        }
    }else if(ProductTypevalue=='4'){
         if(document.getElementById("txtWaterPrice").value==""){
            alert("请填写升贴水价格！");
            document.getElementById("txtWaterPrice").focus();
            return false;
        }
         if(document.getElementById("txtProcessFee").value==""){
            alert("请填写加工费！");
            document.getElementById("txtProcessFee").focus();
            return false;
        }
        
       SumCommodityprices();
        
    }
    
    
    }
    return true;
}

function SumCommodityprices(){
    if(document.getElementById("txtProcessFee").value=="" || document.getElementById("txtWaterPrice").value==""){
        return;
    }
     document.getElementById("txtCommodityprices").value=(98+parseFloat(document.getElementById("txtProcessFee").value)+parseFloat(document.getElementById("txtWaterPrice").value))*parseFloat(document.getElementById("ProductStock").value);  
}
var isFirstSelect=false;
function SelectClass()
{
    var html;
    var classArray = GetClassByParentID(0);
    html = "<select id='firstSelect'  onchange=\"isFirstSelect=true;return slectchild(this.value,this.options[this.selectedIndex].text,0)\">";
    html += "<option value='-1'>请选择...</option>";
    for(var i=0;i<classArray.length;i++)
    { 
        var _name=classArray[i][0];
        if(classArray[i][2]!="0")
        {
            _name = _name + " > ";
        }
        html += "<option value="+classArray[i][1]+">"+_name+"</option>";
    }
    html += "</select>";
     document.getElementById("ClassBarDiv").style.display='block';
    document.getElementById("ChangeClass").style.display='none';
//    var ObjDIV = document.getElementById("ClassBar");
//    ObjDIV.style.display="";
//    ObjDIV.style.position="absolute";
//    document.getElementById("ClassBarContent").innerHTML = html;
//
   document.getElementById("ClassBarDiv").innerHTML = html;
}

function slectchild(id,text,barid)
{
 var ObjDIV = document.getElementById("ClassBarDiv");
    
    if(isFirstSelect)
    {
       var tempSelect =  document.getElementById("firstSelect").cloneNode(true);
       tempSelect.value=id;
       ObjDIV.innerHTML="";
       ObjDIV.appendChild(tempSelect);
       isFirstSelect=false;
        if(id==-1)
         {
            return;
         }
    }

    var html;
    var classArray = GetClassByParentID(id);
    var boj = document.all("hlClassBarItem");

    if(boj=="[object]"){
        var length = 0;
        if(boj.length==undefined){
            length = 1;
        }else{
            length = boj.length;
        }
        for(var j = barid; j < length; j++){
            if(length==1)
            {
                //    document.getElementById("ClassBarContent").removeChild(boj);
                document.getElementById("ClassBarDiv").removeChild(boj);
            }else{
                 // document.getElementById("ClassBarContent").removeChild(boj[barid]);
                document.getElementById("ClassBarDiv").removeChild(boj[barid]);
            }
        }
    }
    var classnameobj = document.all("hlclassname");
    if(classnameobj=="[object]")
    {
   
        var length = 0;
        if(classnameobj.length==undefined){
            length = 1;
        }else{
            length = classnameobj.length;
        }
        for(var j = barid; j < length; j++){
            if(length==1)
            {
                 
                document.getElementById("ClassName").removeChild(classnameobj);
            }else{
                 
                document.getElementById("ClassName").removeChild(classnameobj[barid]);
            }
        }
    }
    
     
   // document.getElementById("ClassName").innerHTML += "<span id='hlclassname'>"+text+"</span>";
    document.getElementById("ClassID").value = id;
    if(classArray.length==0){return;}
//      html = "<span id='hlClassBarItem'><select size='10' onchange=\"return slectchild(this.value,this.options[this.selectedIndex].text,"+ barid + 1 +")\">";
//  
    html = "<select  onchange=\"return slectchild(this.value,this.options[this.selectedIndex].text,"+ barid + 1 +")\">";
     html += "<option value='-1'>请选择...</option>";
    for(var i=0;i<classArray.length;i++)
    {
        var _name=classArray[i][0];
        if(classArray[i][2]!="0")
        {
            _name+=" > ";
        }
        html += "<option value="+classArray[i][1]+" onclick='return slectchild("+classArray[i][1]+")'>"+_name+"</option>";
    }
    html += "</select>";
       // html += "</select></span>";
  // var ObjDIV = document.getElementById("ChangeClass");
//    var ObjDIV = document.getElementById("ClassBarContent");

    ObjDIV.innerHTML += html;
}

function previewImg(file,id)
{
/*
    var previewImage = document.getElementById("previewImage");
    previewImage.innerHTML = "<img src='" + obj + "' width='100' height='100' borber=0 />"
    */
    
      if(navigator.userAgent.indexOf("Mozilla/5.")>-1){
    
     document.getElementById(id).innerHTML = "<img src='"+file.files[0].getAsDataURL()+"' width='100' height='100' borber=0>";
     
 }
 else{


   document.getElementById(id).innerHTML = "<img src='"+file.value+"' width=100 height=100 border=0>";
 
}
   }

//   function ShowViewImg(file,id) {
//      if(navigator.userAgent.indexOf("Mozilla/5.")>-1){
//    
////     document.getElementById(id).innerHTML = "<img src='"+file.files[0].getAsDataURL()+"' width='100' height='100' borber=0>";
//  document.getElementById(id).innerHTML = "<img src='"+file.files[0].getAsDataURL()+"' width='100' height='100' borber=0>";
//  
// }
// else{


//   document.getElementById(id).innerHTML = "<img src='"+file.value+"' width=100 height=100 border=0>";
//   
//   }
//   
//   }

          //上传图片
    function SubmitPicFile(fileUploadId){
           $('#'+fileUploadId).click();
       }

       //发票的更换
       function NeedInvoiceChange() {
           var boj = document.getElementsByName("NeedInvoice");
           var bojvalue;
           for (i = 0; i < boj.length; i++) {
               if (boj[i].checked)
                   bojvalue = boj[i].value;
           }
           if (bojvalue == "1") {
               document.getElementById("trTaxRate").style.display = "block";
           }
           else {
               document.getElementById("trTaxRate").style.display = "none";
           }
       }
        
       
